import 'package:flutter/material.dart';

import '../config/Config.dart';

class RatingWidget extends StatefulWidget {
  final int initialRating;
  final int maxRating;
  final Function(int) onRatingChanged;

  const RatingWidget({
    Key? key,
    this.initialRating = 0,
    this.maxRating = 5,
    required this.onRatingChanged,
  }) : super(key: key);

  @override
  _RatingWidgetState createState() => _RatingWidgetState();
}

class _RatingWidgetState extends State<RatingWidget> {
  int _currentRating = 0;

  @override
  void initState() {
    super.initState();
    _currentRating = widget.initialRating;
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: List.generate(widget.maxRating, (index) {
        return IconButton(
          icon: Icon(
            index < _currentRating ? Icons.star : Icons.star_border,
            color: Config.color5490ff,
            size: 32.0,
          ),
          onPressed: () {
            setState(() {
              _currentRating = index + 1;
            });
            widget.onRatingChanged(_currentRating);
          },
        );
      }),
    );
  }
}